import { user, list } from "./data"
export default {
    //get请求
    'GET /test': { name: "admin", age: 18, location: "get深圳" },
    // post请求
    'POST /admin/base/open/register': (req, res) => {
        // console.log(req.body)
        const { username, password, nickName } = req.body
        let isExist = false;
        user.forEach(item => {
            if (item.name == username) {
                isExist = true
            }
        })
        if (isExist) {
            res.send({
                code: 1001,
                message: '用户已存在'
            })
        } else {
            user.push({
                id: user.length + 1,
                name: username,
                password: password,
                // 审核状态 0 未审核 1 审核通过 2 审核不通过
                checking: 0,
                nickName: nickName
            })
            let indexId = user.length;
            setTimeout(() => {
                user.forEach(item => {
                    if (item.id == indexId) {
                        item.checking = 1
                    }
                })
            }, 10000)
            res.send({
                code: 1000,
                data: {
                    id: user.length,
                    name: username,
                    password: password,
                    // 审核状态 0 未审核 1 审核通过 2 审核不通过
                    checking: 0,
                    nickName: nickName,
                    // 登录token
                    token: 'xxxx'
                }
            })
        }

    },
    'POST /admin/base/open/login': (req, res) => {
        // console.log(req.body)
        const { username, password, isback } = req.body
        let userInfo = {}
        user.forEach(item => {
            if (item.name == username && item.password == password) {
                userInfo = item;
                if (item.checking == 0) {
                    setTimeout(() => {
                        item.checking = 2
                    }, 5000);
                }
            }
        })
        if (Object.keys(userInfo).length > 0) {
            res.send({
                code: 1000,
                data: {
                    // 审核状态 0 未审核 1 审核通过 2 审核不通过
                    // 登录token
                    token: 'xxxx',
                    ...userInfo
                }
            })
        } else {
            res.send({
                code: 1001,
                message: '登录信息错误'
            })
        }
    },
    'POST /admin/base/comm/person': (req, res) => {
        // console.log(req.body)
        const { id } = req.body
        // console.log(user, id)
        let userInfo = {}
        user.forEach(item => {
            if (item.id == id) {
                userInfo = item
            }
        })
        res.send({
            code: 1000,
            data: {
                // 审核状态 0 未审核 1 审核通过 2 审核不通过
                createTime: "2022-11-14 11:39:23",
                isback: false,
                passwordV: 1,
                remark: null,
                updateTime: "2022-11-14 11:39:23",
                ...userInfo
            }
        })
    },
    'POST /admin/base/activityManage/page': (req, res) => {
        // console.log(req.body)
        const { page, size } = req.body
        let pageList = list.slice((page - 1) * size, page * size)
        res.send({
            code: 1000,
            message: "success",
            data: {
                list: pageList,
                pagination: { page: page, size: size, total: list.length },
            },
        })
    },
    'POST /admin/base/activityManage/info': (req, res) => {
        // console.log(req.body)
        const { id } = req.body
        list.forEach(item => {
            if (item.id == id) {
                res.send({
                    code: 1000,
                    message: "success",
                    data: item,
                })
            }
        })

    },
    'POST /app/base/activitySignup/add': (req, res) => {
        // console.log(req.body)
        const { activityId, address, name, phone, userId, wx } = req.body
        res.send({
            code: 1000,
            message: "success",
        })

    },
    'POST /app/base/activitySignup/page': (req, res) => {
        // console.log(req.body)
        const { page, size,status } = req.body
        let newList=[]
        list.forEach(item=>{
            if(item.activityStatus==status){
                newList.push(item)
            }
        })
        let pageList = newList.slice((page - 1) * size, page * size)
        res.send({
            code: 1000,
            message: "success",
            data: {
                list: pageList,
                pagination: { page: page, size: size, total: newList.length },
            },
        })

    }
    
}